package com.example.archivemanagement.controller;

import com.example.archivemanagement.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stats")
@CrossOrigin(origins = "*", maxAge = 3600)
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @GetMapping("/today-visits")
    @PreAuthorize("isAuthenticated()")
    public long getTodayVisits() {
        return statisticsService.getTodayVisits();
    }

    @GetMapping("/month-views")
    @PreAuthorize("isAuthenticated()")
    public long getMonthViews() {
        return statisticsService.getMonthViews();
    }

    @GetMapping("/downloads")
    @PreAuthorize("isAuthenticated()")
    public long getDownloadCount() {
        return statisticsService.getDownloadCount();
    }
}
